#include "Socket.hpp"

using namespace SocketModule;
using namespace LogModule;

class TcpServer
{
public:
    TcpServer(uint16_t port)
        : _port(port),
          // 基类指针指向子类，子类重写了基类需要重写的方法
          _listensocketptr(std::make_unique<TcpSocket>()),
          _isrunning(false)
    {
        // 直接完成了tcp服务器的初始化工作
        _listensocketptr->BuildTcpSocketMethod(_port);
    }

    void Start()
    {
        _isrunning = true;
        while (_isrunning)
        {
            int sockfd = _listensocketptr->Accept();
            LOG(LogLevel::DEBUG) << "server is running...";
        }
        _isrunning = false;
    }

    ~TcpServer() {}

private:
    uint16_t _port; // 端口号
    std::unique_ptr<Socket> _listensocketptr;
    bool _isrunning;
};
